﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;

using TrivialPurfuit.Business;
using TrivialPurfuit.Data;

namespace TrivialPurfuit.Presentation.Edit
{
    /// <summary>
    /// Interaction logic for EditCategoriesView.xaml
    /// </summary>
    public partial class EditCategoriesView : Window
    {
        public EditCategoriesView()
        {
            InitializeComponent();


            ListCollectionView view = new ListCollectionView(Business.QuestionCollection.Categories);

            view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            view.Filter = new Predicate<Object>(CategoriesFilter);
            this.categoryDataGrid.ItemsSource = view;
        }

        private void SaveAndClose_Click(object sender, RoutedEventArgs e)
        {
            //Business.QuestionCollection.saveChanges();
            this.Close();
        }

        private bool CategoriesFilter(object item)
        {
            QuestionCategory categoryRow = (QuestionCategory)item;
            bool keepItem = true; 

            if (categoryRow.ID == CategoryCON.NULL.ID)
                keepItem = false;

            return keepItem;
        }
    }
}
